Skip to content

refactor: move the USD to PHP exchange rate into settings - #36

Merged
Huerte merged 1 commit into
nemsu-dev-org:mainfrom
am-official:refactor/usd-to-php-rate-setting
Oct 25, 2026
Merged

Huerte merged 1 commit into
nemsu-dev-org:mainfrom
am-official:refactor/usd-to-php-rate-setting

Conversation

@am-official

Copy link
Copy Markdown
Contributor

Closes #28

The rate 59.41 was hardcoded in Product.price_in_peso_value under the name PHILIPPINE_PESO_TO_USD, which is the opposite direction of what it converts.

  • settings.py: new USD_TO_PHP_RATE = config('USD_TO_PHP_RATE', default='59.41', cast=Decimal), read with decouple like the other settings. It defaults to 59.41 and can be set from the environment.
  • store/models.py: price_in_peso_value reads settings.USD_TO_PHP_RATE into a variable named usd_to_php, so the name matches the direction. Nothing else in the model changes, so displayed prices stay the same.
  • SETUP.md: lists USD_TO_PHP_RATE=59.41 as an optional variable in the .env example.

I kept it small, as the issue asks; a live exchange rate would be a separate change.

How I tested it

  • New store/tests/test_exchange_rate.py:
    • with the default rate, a $10.00 product still shows ₱594.10;
    • with override_settings(USD_TO_PHP_RATE=Decimal('50.00')), the peso price and the discounted price are 500.00, so the model really uses the setting.
  • Without the model and settings change, these tests fail.
  • python manage.py check is clean and python manage.py test passes (11 tests), using the dummy keys from the CI workflow.
  • USD_TO_PHP_RATE=55.5 in the environment gives Decimal('55.5') in settings.

The rate 59.41 was hardcoded in Product.price_in_peso_value under the name
PHILIPPINE_PESO_TO_USD, which is the opposite direction of what it converts.

settings.USD_TO_PHP_RATE now holds it, read with decouple like the other settings: it defaults to
59.41 and can be set with the USD_TO_PHP_RATE environment variable. The model reads it as
usd_to_php. Displayed prices do not change. SETUP.md lists the optional variable.

Tests check that the default rate gives the same peso price as before and that the model uses
the rate from settings.

Closes nemsu-dev-org#28
@Huerte
Huerte merged commit 2047b4d into nemsu-dev-org:main Oct 25, 2026
1 check passed
@Huerte

Huerte commented Oct 25, 2026

Copy link
Copy Markdown
Member

@am-official

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move the USD to PHP exchange rate out of the Product model

2 participants